home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
- #include <malloc.h>
- #include <direct.h>
- #include <conio.h>
-
- #include "lantasti.h"
- #include "lanctl.h"
-
- #define LIST_SIZE 30
- #define NAME_SIZE 20
-
- typedef struct FLAGS {
- int suppress,
- stop;
- char fname[50];
- } FLAGS;
-
- /* net commands supported by fastnet */
- #define NUM_NET_CMDS 5
- char *net_cmds[] = {
- "USE",
- "UNUSE",
- "CLOCK",
- "LPT",
- "QUEUE",
- };
-
- #define NUM_LPT_CMDS 4
- char *lpt_cmds[] = {
- "TIMEOUT",
- "COMBINE",
- "FLUSH",
- "SEPARATE"
- };
-
- #define NUM_QUEUE_CMDS 6
- char *queue_cmds[] = {
- "START",
- "HALT",
- "STOP",
- "PAUSE",
- "SINGLE",
- "RESTART"
- };
-
- FLAGS flags = {
- FALSE,
- FALSE,
- ""
- };
-
- /* error ********************************************************************
-
- *****************************************************************************/
- void error(code,message)
- int code;
- char *message;
- {
- char *ptr;
-
- if (flags.suppress) return;
-
- if (code) {
- ptr = get_error_text(code);
- puts(ptr);
- }
- else puts(message);
- }
-
- /* find_str ********************************************************************
- Returns -1 if target string not found
- *****************************************************************************/
- int find_str(string,array,n)
- char *string,
- *array[];
- int n;
- {
- int i,found;
-
- found = FALSE;
- for (i = 0; i < n; i++ ) {
- if (!strcmp(string,array[i])) {
- found = TRUE;
- break;
- }
- }
- return((found) ? i : -1);
- }
-
- /* net_use ******************************************************************
-
- *****************************************************************************/
- net_use(cmd)
- char *cmd;
- {
- char device[17],netpath[61],*ptr;
- int type;
-
- type = 4;
-
- device[0] = netpath[0] = 0;
- if (cmd != NULL) strcpy(device,cmd);
-
- if (strlen(device) > 2) {
- if (!strncmp("LPT",device,3)) type = 3;
- if (!strncmp("PRN",device,3)) type = 3;
- }
-
- ptr = strtok(NULL," ");
- if (ptr != NULL) strcpy(netpath,ptr);
-
- return(redirect_device(device,netpath,type));
- }
-
- /* net_unuse ****************************************************************
-
- *****************************************************************************/
- net_unuse(cmd)
- char *cmd;
- {
- char device[17];
-
- device[0] = 0;
- if (cmd != NULL) strcpy(device,cmd);
-
- return(cancel_redirection(device));
- }
-
- /* net_clock ****************************************************************
-
- *****************************************************************************/
- net_clock(cmd)
- char *cmd;
- {
- set_clock(cmd);
- }
-
- /* net_lpt ******************************************************************
-
- *****************************************************************************/
- net_lpt(cmd)
- char *cmd;
- {
- char *ptr;
- int cmd_no,time,ret_code;
-
- ret_code = 0;
- cmd_no = find_str(cmd,lpt_cmds,NUM_LPT_CMDS);
- if (cmd_no >= 0) {
- ptr = strtok(NULL," ");
- switch (cmd_no) {
- case 0: /* timeout */
- time = atoi(ptr);
- ret_code = lpt_timeout(time);
- break;
- case 1: /* combine */
- set_lpt_mode(0);
- break;
- case 2: /* flush */
- flush_lpt();
- break;
- case 3: /* separate */
- set_lpt_mode(1);
- break;
- }
- }
- else {
- error(FALSE,"Invalid NET LPT command");
- ret_code = -1;
- }
- return(ret_code);
- }
-
- /* net_queue ****************************************************************
-
- *****************************************************************************/
- net_queue(cmd)
- char *cmd;
- {
- char *ptr;
- int cmd_no,time,ret_code;
-
- ret_code = 0;
- cmd_no = find_str(cmd,queue_cmds,NUM_QUEUE_CMDS);
- if (cmd_no >= 0) {
- ptr = strtok(NULL," ");
- queue_ctl(cmd_no,ptr);
- }
- else {
- error(FALSE,"Invalid NET QUEUE command");
- ret_code = -1;
- }
- return(ret_code);
- }
-
- /* options */
- #define NUM_OPTIONS 3
- char *options[NUM_OPTIONS] = {
- "STOP",
- "SUPPRESS",
- "HELP"
- };
-
- /* process_option ********************************************************************
-
- *****************************************************************************/
- void process_option(string,flags)
- char *string;
- FLAGS *flags;
- {
- char *ptr;
- int i;
-
- ptr = strtok(string,"=:");
-
- for (i = 0; i < NUM_OPTIONS; i++) {
- if (!strcmpi(ptr,options[i])) break;
- }
-
- if (i >= NUM_OPTIONS) {
- printf("Whoops! %s isn't a valid command line option.\n",ptr);
- return;
- }
-
- ptr = strtok(NULL," =");
-
- switch (i) {
- case 0: /* stop on any error */
- flags->stop = TRUE;
- break;
- case 1: /* suppress error messages */
- flags->suppress = TRUE;
- break;
- case 2: /* help */
- puts("FASTNET utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
- puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
- puts("Usage: FASTNET <file name> [/OPTIONS]");
- puts("FASTNET quickly processes entire files of the most commonly used");
- puts("NET commands. Commands that FASTNET does not recognize will be");
- puts("passed to your normal command interpreter.\n");
- puts("Available options are:");
- puts("/STOP - stop on any error condition");
- puts("/SUPPRESS - suppress all error messages");
- puts("/HELP - display this documentation");
- exit(0);
- break;
- }
- }
-
- /* scan_command_line ********************************************************************
-
- *****************************************************************************/
- scan_command_line(argc,argv,flags)
- int argc;
- char *argv[];
- FLAGS *flags;
- {
- int i,state;
- state=0;
-
- for (i = 1;i < argc; i++) {
- strupr(argv[i]);
- if (argv[i][0] == '/') {
- process_option(&argv[i][1],flags);
- continue;
- }
- switch (state++) {
- case 0: /* first valid arg */
- strcpy(flags->fname,argv[i]);
-
- /* expand fname to ".BAT" if no extension is given */
- if (strchr(flags->fname,'.') == NULL) strcat(flags->fname,".BAT");
- break;
- default:
- error(FALSE,"Extra command line argument ignored.");
- break;
- }
- }
- }
-
- /* do_net_cmd ********************************************************************
-
- *****************************************************************************/
- do_net_cmd(cmd)
- char *cmd;
- {
- int lastchar,cmd_no,ret_code;
- char *ptr,cmd_cpy[81];
-
- ret_code = 0;
- lastchar = strlen(cmd) - 1;
- if (cmd[lastchar] == '\n') cmd[lastchar] = 0;
- strupr(cmd);
- strcpy(cmd_cpy,cmd);
-
- /* see if we've got a net command or some other batch command */
- ptr = strtok(cmd," ");
- if (!strcmp(ptr,"NET")) {
- ptr = strtok(NULL," ");
- cmd_no = find_str(ptr,net_cmds,NUM_NET_CMDS);
- if (cmd_no >= 0) {
- ptr = strtok(NULL," ");
- switch (cmd_no) {
- case 0: /* use */
- ret_code = net_use(ptr);
- break;
- case 1: /* unuse */
- ret_code = net_unuse(ptr);
- break;
- case 2: /* clock */
- net_clock(ptr);
- break;
- case 3: /* lpt */
- net_lpt(ptr);
- break;
- case 4: /* queue */
- net_queue(ptr);
- break;
- }
- } else system(cmd_cpy);
- } else system(cmd_cpy);
- return(ret_code);
- }
-
- /* main ********************************************************************
-
- *****************************************************************************/
- int main(argc,argv)
- int argc;
- char *argv[];
- {
- char buffer[1024];
- FILE *cmdfile;
- char cmd[81];
- int ret_code;
-
- #ifdef SHAREWARE
- puts("FASTNET utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
- puts("All rights reserved. Thanks for trying this unregistered Shareware edition!\n");
- #endif
-
- scan_command_line(argc,argv,&flags);
-
- if (!nos_present()) {
- error(FALSE,"LANtastic is not currently running.");
- return(-1);
- }
-
- cmdfile = fopen(flags.fname,"rt");
- if (cmdfile != NULL) {
- setvbuf(cmdfile,buffer,_IOFBF,sizeof(buffer));
- fgets(cmd,80,cmdfile);
- while (!feof(cmdfile)) {
- ret_code = do_net_cmd(cmd);
- if (ret_code) {
- error(ret_code,NULL);
- if (flags.stop) break;
- }
- fgets(cmd,80,cmdfile);
- }
- fclose(cmdfile);
- }
- else {
- sprintf(buffer,
- "Sorry, I can't open the NET command file. (%s)\n",flags.fname);
- error(FALSE,buffer);
- }
- return(ret_code);
- }